######################################################################
# This file contains configuration information pertaining to the specific
# local setup of EP - the database connection settings (user/pass), etc.
# Edit it to match your system and then create the following symlink:
#
# From: {ROOT}/cgi-lib/perl/EP/Config.pm, To: this file.
#
# You can do this, e.g., by running the following command (from cgi-lib/perl/EP):
#   ln -sf ../../../conf/Config_local.pm Config.pm
#
# Or, you can just copy Config_local.pm to Config.pm in cgi-lib/perl/EP.
######################################################################
package EP::Config;
use strict;

$ENV{ORACLE_HOME} = ""; # You may need this if running on Oracle - it should match $ORACLE_HOME in your environment
$ENV{R_HOME}      = ""; # location of your R installation
$ENV{DISPLAY}     = ""; # X11 display
$ENV{PGPLOT_DIR}  = ""; # location of your PGPLOT installation
$ENV{http_proxy}  = ""; # required for accessing the internet (R/biomaRt)

require Exporter;
our @ISA = qw ( Exporter );
our @EXPORT = qw ( DEBUG ORACLE );

use vars qw ( $h );
use DBI;

use IO::Handle;
STDERR->blocking(0);

use constant DEBUG  => 2; # Toggle debugging output verbosity (0 - none)
use constant ORACLE => 0; # Set to 1 if running on Oracle.

$h->{DEBUG} = DEBUG;

#main directories
$h->{ROOT} = ""; # The root directory of EP installation

$h->{CGI_ROOT}  = "$h->{ROOT}/cgi-bin";
$h->{HTML_ROOT} = "$h->{ROOT}";
$h->{CGI_HREF}  = "";
$h->{HTML_HREF} = "";
$h->{CORE_HREF} = "";

# AE - set these only if you are going to connect to AE directly. If you're not inside EBI, you are most likely not
# going to (be allowed to) do that.
$h->{AE_DB} = "";
$h->{AE_DBUSER} = "";
$h->{AE_DBPASSWORD} = "";
$h->{AE_DBATTR} =
    { RaiseError => 1
    , PrintError => 0               # only print errors with our own error handling means
    , AutoCommit => 1
    , LongReadLen => 32768          # set this up to retrieve long data fields (a_session in sessions)
    , FetchHashKeyName => "NAME_lc" # convert field names to lower case (Oracle keeps them in upper)
    };


# EP database connection (change to your system's settings)
$h->{DB} = "dbi:Pg:dbname="; # if running on Oracle, might need dbi:Oracle:sid= etc.
$h->{DBUSER} = "";
$h->{DBPASSWORD} = "";
$h->{DBATTR} =
    { RaiseError => 1
    , PrintError => 0               # only print errors with our own error handling means
    , AutoCommit => 1
    , LongReadLen => 32768          # set this up to retrieve long data fields (a_session in sessions)
    , FetchHashKeyName => "NAME_lc" # convert field names to lower case (Oracle keeps them in upper)
    };

# TODO: this document is loaded all the time... perhaps we should move
# the DBI connection somewhere else?
$h->{DBH} = DBI->connect( $h->{DB}, $h->{DBUSER}, $h->{DBPASSWORD}, $h->{DBATTR} ) or
    die "Couldn't open connection to the database: $DBI::errstr\n";

# Uncomment to obtain a lot of database connection trace code in stderr. Set to higher values for more.
#$h->{DBH}->trace(1);

# EPNG data configuration
$h->{EPNG_DATA_PATH} = "$h->{ROOT}/data";           # Physical location of the data files - only need this for CORE
$h->{EPNG_DATA_URL}  = "$h->{HTML_HREF}/data";      # URL to the data files - note how insecure this is at the moment!!! (TODO)
$h->{TSA_DATA_PATH}  = "$h->{EPNG_DATA_PATH}/tsa";  # Physical location
$h->{TSA_DATA_URL}   = "$h->{EPNG_DATA_URL}/tsa";   # Physical location

#external programs
$h->{GET_CMD} = "/usr/bin/wget -q -O-";
$h->{NCDUMP_CMD} = "/usr/bin/ncdump";
$h->{JAVA_CMD} = "/usr/bin/java";
$h->{NICE_CMD} = "/usr/bin/nice";
$h->{TIME_CMD} = "/usr/bin/time";
$h->{PS_CMD} = "/bin/ps";
$h->{CONVERT_CMD} = "/usr/bin/convert";

# queuing type
# # can be off LINUX, PBS, LSF
$h->{JOB_QUEUE} = "UNIX";

# GFF settings - slightly messy config for the sequence (genome) databases - see Config_global.pm for more info.
$h->{GFF_DSN_PREFIX} = "dbi:Pg:host=localhost";
$h->{GFF_DSN_USER} = "";

#include stuff from global configuration file
require EP::Config_global;

1;
